package com.sunsy.authserver.config;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 孙思远
 * @date 2021/7/19
 */

public class MvcInterceptorConfig implements WebMvcConfigurer {

  private List<HandlerInterceptor> interceptors = new ArrayList<>();

  public MvcInterceptorConfig(HandlerInterceptor... interceptors) {
    for (HandlerInterceptor interceptor : interceptors) {
      this.interceptors.add(interceptor);
    }
  }

  @Override
  public void addInterceptors(InterceptorRegistry registry) {
    interceptors.forEach(interceptor -> registry.addInterceptor(interceptor));

  }
}
